//和为 K 的子数组
https://leetcode.cn/problems/subarray-sum-equals-k/description/

class Solution {
public:
    int subarraySum(vector<int>& nums, int k) 
    {
        int n = nums.size();
        int ret = 0;
        int sum = 0;
        unordered_map<int,int> map;
        map.insert(make_pair(0,1));
        for(int i = 0; i < n; i++)
        {
            sum += nums[i];
            int tmp = sum - k;
            auto it = map.find(tmp);
            if(it != map.end())
            {
                ret += it->second;
            }
            map[sum]++;
        }
        return ret;
    }
};